﻿
@using MvcForum.Web.Application.ExtensionMethods
@model MvcForum.Web.ViewModels.Topic.CreateEditTopicViewModel
@{
    var count = 0;
    const string displayNone = "style=\"display: none;\"";
    ViewBag.ImageUploadType = Model.OptionalPermissions.CanInsertImages ? "forumimageinsert" : "image";    
}

@Html.HiddenFor(x => x.TopicId)
@if (Model.IsTopicStarter)
{
    <div class="row paddedrow">
        <div class="col-md-8 topictitleholder">
            <h2>@ViewBag.Title</h2>
        </div>
        @if (Html.Settings().EnablePolls == true)
        {
            <div class="col-md-4 pollcreatebuttonholder" @Html.Raw(Model.OptionalPermissions.CanCreatePolls ? "" : displayNone)>
                <a href="#" class="btn-mvc btn-mvc-fullwidth createpollbutton">@Html.LanguageString("Poll.Button.Create")</a>
                <a href="#" style="display: none;" class="btn-mvc btn-mvc-fullwidth removepollbutton">@Html.LanguageString("Poll.Button.Remove")</a>
            </div>
        }
    </div>

    <div class="paddedrow topicname">
        <div class="form-group">
            @Html.LabelFor(model => model.Name)
            @Html.TextBoxFor(model => model.Name, new { @class = "createtopicname form-control" })
            @Html.ValidationMessageFor(model => model.Name)
        </div>
    </div>

    <div class="row paddedrow relatedtopicsholder">
        <div class="col-md-12 relatedtopics">
            <h5>@Html.LanguageString("Topic.AlreadyAnswered")</h5>
            <div class="relatedtopicskey"></div>
        </div>
    </div>

    if (Html.Settings().EnablePolls == true)
    {
        <div class="pollanswerholder" @Html.Raw(Model.PollAnswers != null && Model.PollAnswers.Any() ? "" : displayNone)>
            <div class="row paddedrow">
                <div class="col-md-9">

                    <ul class="pollanswerlist">
                        @if (Model.PollAnswers != null && Model.PollAnswers.Any())
                        {
                            foreach (var pollAnswer in Model.PollAnswers.OrderBy(x => x.Answer))
                            {
                                <li id="answer@(count)">
                                    <input type="text" name="PollAnswers[@(count)].Answer" id="PollAnswers_@(count)_Answer" value="@pollAnswer.Answer" class="form-control" placeholder="@Html.LanguageString("Poll.Placeholder.TypeAnswerHere")" @Html.Raw(pollAnswer.PollVotes.Any() ? "disabled" : "") />
                                    <input type="hidden" value="@pollAnswer.Id" name="PollAnswers[@(count)].Id" id="PollAnswers_@(count)Id" />
                                </li>

                                count++;
                            }
                        }
                    </ul>
                    <input type="hidden" id="pollanswerplaceholder" value="@Html.LanguageString("Poll.Placeholder.TypeAnswerHere")" />
                </div>
                <div class="col-md-3 polladdremovenewanswers">
                    <a href="#" class="btn-mvc addanswer">
                        <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                    </a>
                    <a href="#" class="btn-mvc removeanswer">
                        <span class="glyphicon glyphicon-minus" aria-hidden="true"></span>
                    </a>
                </div>
            </div>
            <div class="paddedrow pollcloseafterdays">
                <div class="form-group">
                    @Html.LabelFor(model => model.PollCloseAfterDays)
                    @Html.TextBoxFor(model => model.PollCloseAfterDays, new { @class = "form-control", type = "number" })
                    @Html.ValidationMessageFor(model => model.PollCloseAfterDays)
                </div>
            </div>
        </div>
    }

    <div class="form-group">
        @Html.LabelFor(model => model.Category)
        @Html.DropDownListFor(model => model.Category, Model.Categories, new { @class = "form-control" })
        @Html.ValidationMessageFor(model => model.Category)
    </div>
    <div class="form-group">
        <label>@Html.Lang("Topic.Label.Tags")</label>
        <div class="topictagholder">
            @Html.TextAreaFor(model => model.Tags, new { @class = "tagstextarea tags", title = Html.LanguageString("Topic.TagThisTopic") })
        </div>
    </div>
}
else
{
    <h2>@ViewBag.Title</h2>
    @Html.HiddenFor(x => x.Category)
    @Html.HiddenFor(x => x.Name)
}



<div class="row">
    <div class="col-md-12 topiccontent">
        <div class="editor-field editorholder">
            @Html.EditorFor(model => model.Content)
            @Html.ValidationMessageFor(model => model.Content)
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-6 createtopicbuttonholder">
        <div class="submit-holder">
            <button type="submit" class="btn-mvc-green btn-mvc-large btn-mvc-fullwidth">
                @if (Model.Id == Guid.Empty)
                {
                    @Html.LanguageString("Topic.CreateDiscussion")
                }
                else
                {
                    @Html.LanguageString("Post.Edit")
                }
            </button>
        </div>
        @if (Model.IsTopicStarter)
        {
            <div class="checkbox createsubscribe">
                @using (Html.BeginLabelFor(m => m.SubscribeToTopic, new { @class = "checkbox" }))
                {
                    @Html.CheckBoxFor(m => m.SubscribeToTopic)
                }
                @Html.ValidationMessageFor(m => m.SubscribeToTopic)
            </div>
            <div class="checkbox createsticky" @Html.Raw(Model.OptionalPermissions.CanStickyTopic ? "" : displayNone)>
                @using (Html.BeginLabelFor(m => m.IsSticky, new { @class = "checkbox" }))
                {
                    @Html.CheckBoxFor(m => m.IsSticky)
                }
                @Html.ValidationMessageFor(m => m.IsSticky)
            </div>
            <div class="checkbox createlocked" @Html.Raw(Model.OptionalPermissions.CanLockTopic ? "" : displayNone)>
                @using (Html.BeginLabelFor(m => m.IsLocked, new { @class = "checkbox" }))
                {
                    @Html.CheckBoxFor(m => m.IsLocked)
                }
                @Html.ValidationMessageFor(m => m.IsLocked)
            </div>
        }
    </div>

    @if (Model.IsTopicStarter)
    {
        <div class="col-md-5 col-md-offset-1 topiccategory">

            @if (Model.Id == Guid.Empty)
            {
                <div class="form-group createuploadfiles" @Html.Raw(Model.OptionalPermissions.CanUploadFiles ? "" : displayNone)>
                    @Html.LabelFor(x => x.Files)
                    <div class="input-group">
                        <span class="input-group-btn">
                            <span class="btn btn-default btn-file">
                                @Html.LanguageString("Post.Browse") <input type="file" name="files" id="files" value="">
                            </span>
                        </span>
                        <input type="text" class="form-control" readonly="">
                    </div>
                    @Html.ValidationMessageFor(x => x.Files)
                </div>
            }
        </div>
    }

</div>